package org.zs.miracle.service.notice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.zs.miracle.common.base.dto.BaseManyLongIdDTO;
import org.zs.miracle.common.util.ModelMapperUtil;
import org.zs.miracle.entity.notice.NoticeEntity;
import org.zs.miracle.mapper.NoticeMapper;
import org.zs.miracle.service.notice.INoticeService;
import org.zs.miracle.service.notice.model.dto.AddNoticeDTO;
import org.zs.miracle.service.notice.model.dto.EditNoticeDTO;
import org.zs.miracle.service.notice.model.dto.NoticeQueryPageDTO;
import org.zs.miracle.service.notice.model.vo.NoticeVO;

/**
 * 通知公告表Service服务接口实现层
 */
@Service
@AllArgsConstructor
public class INoticeServiceImpl implements INoticeService {
  
  @Resource
  NoticeMapper noticeMapper;
  
  @Override
  public Page<NoticeVO> pageQueryList(NoticeQueryPageDTO inputDTO) {
    
    // 构建查询条件
    LambdaQueryWrapper<NoticeEntity> queryWrapper = Wrappers.lambdaQuery();
    
    // 执行查询用户
    Page<NoticeVO> page =
        noticeMapper.selectPage(inputDTO.toMybatisPageObject(), queryWrapper, NoticeVO.class);
    
    return page;
  }
  
  @Override
  public Boolean delNotice(BaseManyLongIdDTO inputDTO) {
    
    // 删除用户
    noticeMapper.deleteByIds(inputDTO.getIds());
    return true;
  }
  
  @Override
  public Boolean addNotice(AddNoticeDTO inputDTO) {
    
    // 将DTO转换为实体对象
    NoticeEntity addEntity = ModelMapperUtil.map(inputDTO, NoticeEntity.class);
    // 插入数据库
    noticeMapper.insert(addEntity);
    
    return true;
  }
  
  @Override
  public Boolean editNotice(EditNoticeDTO inputDTO) {
    
    // 更新的数据
    NoticeEntity updateEntity = ModelMapperUtil.map(inputDTO, NoticeEntity.class);
    
    // 执行更新
    noticeMapper.updateById(updateEntity);
    
    return true;
  }
}